<template>
  <div>
    <el-dialog
      title="修改客户经理"
      :visible.sync="dialogVisible"
      width="600px"
      :before-close="handleClose"
    >
      <el-form
        :model="form"
        :rules="rules"
        ref="form"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="客户经理" prop="accountManager">
          <el-select
            style="width: 400px"
            v-model="form.accountManager"
            placeholder="请选择客户经理"
          >
            <el-option
              v-for="item in managerList"
              :key="item.adminId"
              :label="item.nickName"
              :value="item.adminId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('form')">保存</el-button>
          <el-button @click="dialogVisible = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { getCustomerManagerList } from "@/api/customer";
import { bindkeyike } from "@/api/incomingManagement";

export default {
  name: "editManager",
  data() {
    return {
      dialogVisible: false,
      form: {
        id: "",
        accountManager: ""
      },
      managerList: [],
      rules: {
        accountManager: [
          { required: true, message: "请选择客户经理", trigger: "change" }
        ]
      }
    };
  },

  methods: {
    submitForm(form) {
      this.$refs[form].validate(valid => {
        if (valid) {
          console.log(this.form);
          bindkeyike(this.form).then(res => {
            this.$message({
              type: "success",
              message: "修改成功!"
            });
            this.form.accountManager = "";
            this.form.id = "";
            this.dialogVisible = false;
          });
          this.$emit("getList");
          this.dialogVisible = false;
        } else {
          return false;
        }
      });
    },
    getManagerList() {
      getCustomerManagerList().then(res => {
        this.managerList = res.data;
      });
    },
    opendialog(v) {
      this.form.id = v.id;
      this.dialogVisible = true;
      this.getManagerList();
    },
    handleClose(done) {
      this.dialogVisible = false;
    }
  }
};
</script>

<style scoped lang="scss"></style>
